package club.easin.sq.bl;

import club.easin.common.DatagridRequestDto;
import club.easin.sq.dao.SqNoticeMapper;
import club.easin.sq.dto.SqNotice;
import club.easin.utils.*;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class Noticebl {
    @Autowired
    private SqNoticeMapper sqNoticeMapper;
    @Autowired
    private DBSubmit dbSubmit;

    public ReturnDto addNotice(SqNotice sqNotice){
        Tlist tlist=new Tlist();
        sqNotice.setCreatetime(DateUtils.getNow());
        sqNotice.setUpdatetime(DateUtils.getNow());
        sqNotice.setNoticeid(Commutils.buildId());
        tlist.add(SqNoticeMapper.class,"insert",sqNotice);
        dbSubmit.exce(tlist);
        return ReturnUtils.returnsuccess();
    }

    public ReturnDto editNotice(SqNotice sqNotice){
        Tlist tlist=new Tlist();
        sqNotice.setUpdatetime(DateUtils.getNow());
        tlist.add(SqNoticeMapper.class,"updateByPrimaryKeySelective",sqNotice);
        dbSubmit.exce(tlist);
        return ReturnUtils.returnsuccess();
    }

    public ReturnDto delNotice(String noticeid){
        Tlist tlist=new Tlist();
        String[] ids=noticeid.split(",");
        for(String id:ids){
            tlist.add(SqNoticeMapper.class,"deleteByPrimaryKey",id);
        }
        dbSubmit.exce(tlist);
        return ReturnUtils.returnsuccess();
    }

    public ReturnDto getNoticeGrild(DatagridRequestDto dto){
        Page<SqNotice> page=null;
        PageHelper.startPage(dto.getPagenum(),dto.getPagesize());
        page=sqNoticeMapper.getNoticeGrild();
        return ReturnUtils.returnsuccess(DataGrildUtils.returnDataGrild(page));
    }
}
